Imports System.Data
Imports System.Data.OleDb
Imports Microsoft.Win32
Public Class gestSettori
    Inherits System.Web.UI.Page

    'Protected WithEvents opName As System.Web.UI.HtmlControls.HtmlInputHidden
    'Protected WithEvents lkSalva As System.Web.UI.WebControls.LinkButton
    'Protected WithEvents lkAnnulla As System.Web.UI.WebControls.LinkButton
    'Protected WithEvents lkElenco As System.Web.UI.WebControls.LinkButton
    Protected WithEvents Dataset11 As dsSettore
    Protected WithEvents SqlSelectCommand1 As System.Data.SqlClient.SqlCommand
    Protected WithEvents SqlInsertCommand1 As System.Data.SqlClient.SqlCommand
    Protected WithEvents SqlUpdateCommand1 As System.Data.SqlClient.SqlCommand
    Protected WithEvents SqlDeleteCommand1 As System.Data.SqlClient.SqlCommand
    Protected WithEvents SqlConnection1 As System.Data.SqlClient.SqlConnection
    Protected WithEvents da As System.Data.SqlClient.SqlDataAdapter
    'Protected WithEvents lbTitolo As System.Web.UI.WebControls.Label
    'Protected WithEvents dAlbo As System.Web.UI.WebControls.DropDownList


    Dim ParentTable As String = "Tabella"

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Dataset11 = New dsSettore
        Me.da = New System.Data.SqlClient.SqlDataAdapter
        Me.SqlInsertCommand1 = New System.Data.SqlClient.SqlCommand
        Me.SqlConnection1 = New System.Data.SqlClient.SqlConnection
        Me.SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand
        Me.SqlUpdateCommand1 = New System.Data.SqlClient.SqlCommand
        Me.SqlDeleteCommand1 = New System.Data.SqlClient.SqlCommand
        CType(Me.Dataset11, System.ComponentModel.ISupportInitialize).BeginInit()
        '
        'Dataset11
        '
        Me.Dataset11.DataSetName = "DataSet1"
        Me.Dataset11.Locale = New System.Globalization.CultureInfo("en-US")
        '
        'da
        '
        Me.da.InsertCommand = Me.SqlInsertCommand1
        Me.da.SelectCommand = Me.SqlSelectCommand1
        Me.da.UpdateCommand = Me.SqlUpdateCommand1
        '
        'SqlInsertCommand1
        '
        Me.SqlInsertCommand1.CommandText = "INSERT INTO Settori (descrizione, sezione, albo) VALUES (@descrizione, @sezione, @albo); SELEC" & _
        "T codice, descrizione, sezione, albo FROM Settori WHERE (codice = @@IDENTITY)"
        Me.SqlInsertCommand1.Connection = Me.SqlConnection1
        Me.SqlInsertCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@descrizione", System.Data.SqlDbType.VarChar, 50, "descrizione"))
        Me.SqlInsertCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@sezione", System.Data.SqlDbType.Char, 1, "sezione"))
        Me.SqlInsertCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@albo", System.Data.SqlDbType.SmallInt, 2, "albo"))
        '
        'SqlSelectCommand1
        '
        Me.SqlSelectCommand1.CommandText = "SELECT codice, descrizione, sezione, albo FROM Settori"
        Me.SqlSelectCommand1.Connection = Me.SqlConnection1
        '
        'SqlUpdateCommand1
        '
        Me.SqlUpdateCommand1.CommandText = "UPDATE Settori SET descrizione = @descrizione, sezione=@sezione WHERE (codice = @" & _
        "Original_codice) AND (descrizione = @Original_descrizione OR @Original_descrizio" & _
        "ne IS NULL AND descrizione IS NULL); SELECT codice, descrizione, sezione, albo FROM Se" & _
        "ttori WHERE (codice = @codice)"
        Me.SqlUpdateCommand1.Connection = Me.SqlConnection1
        Me.SqlUpdateCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@descrizione", System.Data.SqlDbType.VarChar, 50, "descrizione"))
        Me.SqlUpdateCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@sezione", System.Data.SqlDbType.Char, 1, "sezione"))
        Me.SqlUpdateCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_codice", System.Data.SqlDbType.SmallInt, 2, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "codice", System.Data.DataRowVersion.Original, Nothing))
        Me.SqlUpdateCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_descrizione", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "descrizione", System.Data.DataRowVersion.Original, Nothing))
        Me.SqlUpdateCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@codice", System.Data.SqlDbType.SmallInt, 2, "codice"))
        CType(Me.Dataset11, System.ComponentModel.ISupportInitialize).EndInit()

        Me.SqlConnection1.ConnectionString = ConfigurationSettings.AppSettings("ConnString")

    End Sub

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    'Protected WithEvents UcTestata1 As ucTestata


    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        If (Not Me.IsPostBack) Then

            If Not UcTestata1.carica() Then
                Response.Redirect("..\errore.htm")
            End If

            If Session("albo") = 13 Then
                lbTitolo.Text = "Specializzazioni"
            Else
                lbTitolo.Text = "Settori"
            End If

            dAlbo.DataSource = (New AnaIscritto).elencoAlbi("")
            dAlbo.DataBind()
            dAlbo.SelectedValue = Session("albo")

            populateDataSet()
        End If
        'Put user code to initialize the page here
    End Sub
    Private Sub populateDataSet()

        If dAlbo.SelectedValue <> "" Then
            da.SelectCommand.CommandText = "SELECT codice, descrizione, sezione FROM Settori where albo=" & dAlbo.SelectedValue

            da.Fill(Dataset11, ParentTable)
        End If

    End Sub

 



    Private Sub lkSalva_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lkSalva.Click
        Try

            'Call update on the adapter to commit the changes, catch any exceptions that may be raised.
            da.Update(Dataset11.Tables(ParentTable))

        Catch ex As Exception
            Dataset11.RejectChanges()
        End Try
    End Sub

    Private Sub lkAnnulla_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lkAnnulla.Click
        Dataset11.RejectChanges()
 
    End Sub

    Private Sub lkElenco_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lkElenco.Click
        Response.Redirect("elencoG.aspx")
    End Sub

    
    Private Sub dAlbo_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dAlbo.SelectedIndexChanged
        populateDataSet()

    End Sub
End Class
